package com.matrix.draft.sockettest.groupchatroom.server;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class AcceptKeyEventHandler implements KeyEventHandler{
    @Override
    public void handle(SelectionKey key) {
        try {
            ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();
            SocketChannel socketChannel = serverSocketChannel.accept();
            socketChannel.configureBlocking(false);
            socketChannel.register(key.selector(),SelectionKey.OP_READ);
            System.err.println(socketChannel.hashCode()+"上线了...");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
